
import os
debugging = False
# if not debug mode then don't log to file or console
if not debugging:
    os.environ['KIVY_NO_FILELOG'] = '1'
    os.environ['KIVY_NO_CONSOLELOG'] = '1'

from kivy.logger import Logger

import kivy
kivy.require('1.8.0')

from kivy.app import App
from kivy.config import Config
from kivy.logger import Logger
from kivy.metrics import dp, sp

from dryfire.model.targetsModel import HipsAndHeadDryFireTargetModel
from dryfire.view.appView import AppView
from dryfire.model.persistentData import RangesModel, CalibrationsModel

class DryFireApp(App):
    """
    this is the application class.
    the build method creates and returns an AppView object.
    that AppView object calls the other views.
    those views setup thier view models.
    """
    icon = 'dryfire_64.png'


    def build(self):
        """
        appdata is a dictionary of application wide data.
        App.get_running_app().appdata
        """
        self.appdata = {}
        self.appdata['version'] = {'major': 4, 'minor': 0, 'bugfix': 0}
        # debug mode
        self.appdata['debug'] = debugging
        # target view model
        self.appdata['target_vm'] = None
        # ranges view model
        self.appdata['ranges_view'] = None
        # where the persistent data is stored
        self.appdata['user_data_dir'] = os.path.realpath(self.directory)
        # persistent data
        self.appdata['ranges'] = RangesModel(self.appdata['user_data_dir'])
        self.appdata['calibrations'] = CalibrationsModel(self.appdata['user_data_dir'])

        app_view = AppView(size_hint=(1.0, 1.0))
        self.appdata['app_view'] = app_view
        # self.appdata['app_view'] = TargetButtonSelect(size_hint=(1.0, 1.0))
        return self.appdata['app_view']

    def on_start(self):
        pass

    def on_pause(self):
        self.appdata ['app_view'].visible = False
        return True

    def on_resume(self):
        pass

    def on_stop(self):
        self.appdata ['target_vm'].visible = False

# Config.set('graphics', 'fullscreen', 'auto')
app = DryFireApp()
# Logger.info('user data at :' + app.appdata['user_data_dir'])
app.run()
